package lanou.autohome.forum.fragments;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;

import lanou.autohome.GroupActivity;
import lanou.autohome.MainActivity;
import lanou.autohome.R;
import lanou.autohome.URLValues;
import lanou.autohome.basetool.BaseFragment;

/**
 * Created by dllo on 16/8/15.
 * 论坛 -> 精选推荐
 */
public class ForumFeaturedFragment extends BaseFragment implements View.OnClickListener {

    private TabLayout tabLayout;
    private FrameLayout frameLayout;
    private ImageButton imageButton;

    @Override
    protected int setLayout() {
        return R.layout.fragment_forum_featured;
    }

    @Override
    protected void initView() {
        tabLayout = bindVie(R.id.tablayout_forum_featured);
        frameLayout = bindVie(R.id.frame_forum_featured);
        imageButton = bindVie(R.id.quanbu_imagebtn_forum_featured);

        imageButton.setOnClickListener(this);

    }

    @Override
    protected void intiData() {

        String[] strs = new String[]{"全部", "媳妇当车模", "美人计", "论坛名人堂", "论坛讲师", "精挑细选", "现身说法",
                "高端阵地", "电动车", "汇买车", "行车点评", "超级试驾员", "海外购车", "经典老车", "妹子选车", "优惠购车", "原创大片",
                "顶配风采", "改装有理", "养车有道", "首发阵营", "新车直播", "历史选题", "摩友天地", "蜜月之旅", "甜蜜婚礼", "摄影课堂",
                "车友聚会", "单车部落", "杂谈俱乐部", "华北游记", "西南游记", "东北游记", "西北游记", "华中游记", "华南游记", "华东游记",
                "港澳台游记", "海外游记", "沧海遗珠"};
        for (int i = 0; i < strs.length; i++) {
            TabLayout.Tab tab = tabLayout.newTab();
            tab.setText(strs[i]);
            tabLayout.addTab(tab);
        }

        final String url[] = new String[]{URLValues.FOURM_URL, URLValues.WIFE_MODEL_URL, URLValues.NOTORIOUS_URL,
                URLValues.HOF_URL, URLValues.LECTURER_URL, URLValues.AUSLESE_URL, URLValues.DISCOURSE_URL,
                URLValues.HIGH_POINT_URL, URLValues.ELECTRIC_VEHICLE_URL, URLValues.BUY_CAR_URL, URLValues.DRIVING_CRITIQUE_URL,
                URLValues.DRIVING_MEMBER_URL, URLValues.OVERSEAS_BUYERSL_URL, URLValues.CLASSIC_CAR_URL, URLValues.SISTER_CAR_URL,
                URLValues.PREFERENTIAL_CAR_URL, URLValues.ORIGINAL_LARGE_URL, URLValues.TOP_ELEGANT_URL, URLValues.MODIFIED_RATIONAL_URL,
                URLValues.FIRST_CAMP_URL, URLValues.NEW_LIVE_URL, URLValues.HISTORICAL_TOPIC_URL, URLValues.WAY_MOTORING_URL,
                URLValues.FRIEND_HEAVEN_EARTH_URL, URLValues.HONEYMOON_URL, URLValues.SWEET_WEDDING_URL, URLValues.PHOTOGRAPHY_CLASS_URL,
                URLValues.CAR_PARTY_URL, URLValues.BIKE_TRIBE_URL, URLValues.GOSSIP_CLUB_URL, URLValues.NORCO_TRAVELS_URL,
                URLValues.SOUTHWEST_TRAVELS_URL, URLValues.NORTHEAST_TRAVELS_URL, URLValues.NORTHWEST_TRAVELS_URL, URLValues.SKY_TRAVELS_URL,
                URLValues.SOUTH_TRAVELS_URL, URLValues.HYZ_TRAVELS_URL, URLValues.MACAO_TRAVELS_URL, URLValues.OVERSEAS_TRAVELS_URL,
                URLValues.SEA_PEARL_URL};

        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                FragmentManager fragmentmanager = getChildFragmentManager();
                ForumFeatureAllFragment fragment = new ForumFeatureAllFragment();
                Bundle bundle = new Bundle();
                bundle.putString("url", url[tab.getPosition()]);
                fragment.setArguments(bundle);
                fragmentmanager.beginTransaction().replace(R.id.frame_forum_featured, fragment).commit();
                Log.d("ForumFeaturedFragment", "tab.getPosition():" + tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        tabLayout.getTabAt(1).select();
        tabLayout.getTabAt(0).select();

    }

    //点击打开抽屉
    @Override
    public void onClick(View v) {
        GroupActivity groupActivity = (GroupActivity) getActivity();
        groupActivity.openDrawer();

    }
}

